package com.dfrz.household.controller;


import com.dfrz.household.bean.City;
import com.dfrz.household.bean.Company;
import com.dfrz.household.bean.Province;
import com.dfrz.household.bean.ServerPerson;
import com.dfrz.household.service.ICompanyService;
import com.dfrz.household.service.IProvinceService;
import com.dfrz.household.service.IServerPersonService;
import com.dfrz.household.service.ServerPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
public class ProvinceController {
    @Autowired
    IProvinceService provinceService;
    @Autowired
    ServerPersonService serverPersonService;
    @Autowired
    ICompanyService companyService;

    @RequestMapping("/tocity")
    public ModelAndView roprovince(){
        ModelAndView mv=new ModelAndView();
        List<Province> allProvince = provinceService.getAllProvince();
        mv.addObject("citys",allProvince);
        mv.setViewName("city");
        return mv;
    }
    @RequestMapping("/tocitysite/{id}")
    public ModelAndView rocitysite(@PathVariable Integer id){
        ModelAndView mv=new ModelAndView();
        List<ServerPerson> allTopFive = serverPersonService.getAllSerperson();
        City city = provinceService.getCity(id);
        List<Company> topFiveCompany = companyService.getAllCompany();
        mv.addObject("citydata",city);
        mv.addObject("topdata",allTopFive);
        mv.addObject("companydata",topFiveCompany);
        mv.setViewName("citysite");
        return mv;
    }
}
